<!-- 本页数据在126行 -->
<template>
    <div>
        <el-page-header content="已投递简历" icon="" title="就业管理系统" />

        <el-row :gutter="20" class="el-row">
            <el-col :span="6">
                <el-card class="box-card">
                    <div v-for="item in state.Cvs">
                        <div class="mb-4">
                            <el-button :key="item.title" type='' @click="clickCv(item.id)">
                                {{ item.title }}
                            </el-button>
                        </div>
                    </div>

                </el-card>
            </el-col>
            <el-col :span="18">
                <el-card>
                    <template #header>
                        <div class="card-header">
                            <span>编辑简历</span>
                        </div>
                    </template>

                    <el-form ref="userFormRef" :model="userForm" :rules="userFormRules" label-width="120px"
                        class="demo-ruleForm">
                        <el-form-item label="标题" prop="title">
                            {{ state.userForm.title }}
                        </el-form-item>
                        <el-form-item label="求职意向" prop="job_prefer">
                            {{ state.userForm.job_prefer }}
                        </el-form-item>
                        <el-form-item label="培训经历" prop="education_exp">
                            {{ state.userForm.education_exp }}
                        </el-form-item>
                        <el-form-item label="项目经历" prop="project_exp">
                            {{ state.userForm.project_exp }}
                        </el-form-item>
                        <el-form-item label="实习经历" prop="internship">
                            {{ state.userForm.internship }}
                        </el-form-item>
                        <el-form-item label="获奖经历" prop="price">
                            {{ state.userForm.price }}
                        </el-form-item>
                        <el-form-item label="其他优势" prop="other_advantage">
                            {{ state.userForm.other_advantage }}
                        </el-form-item>

                        <el-form-item label="简历" prop="cv">
                            <!-- <el-link href=state.userForm.cvURL target="_blank">{{ state.userForm.cvURL }}</el-link> -->
                            <el-link @click="handleCv(state.userForm.cvURL)">{{ state.userForm.cvURL }}</el-link>
                        </el-form-item>

                        <el-form-item label="评价与建议" prop="advice">
                            <el-input v-model="state.advice" />
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="submitForm(state.userForm.id)">提交评价</el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-col>
        </el-row>


        <el-dialog v-model="dialogVisible" width="80%">
            <!-- <iframe :src="state.userForm.cvURL" frameborder="0" width="100%" height="600"></iframe> -->
            简历存储地址：{{ state.userForm.cvURL }}
            复制简历地址直接粘贴至浏览器地址栏即可访问
        </el-dialog>
    </div>
    
</template>
<script setup>
import { useStore } from "vuex";
import { computed, ref, reactive, onBeforeMount, guardReactiveProps } from "vue";
import axios from 'axios'
import { ElMessage,ImageProps } from "element-plus";
import upload from '@/util/upload'
import Upload from '@/components/upload/Upload'
import router from "@/router";
import { useRoute } from "vue-router";
const route = useRoute()
onBeforeMount(() => {
    getCvs(store.state.userInfo.id)
})

const store = useStore()
let dialogVisible = ref(false)
const userFormRef = ref()
let state = reactive({
    userForm:{//简历信息
        id: '',
        title: '',
        job_prefer: '',
        education_exp: '',
        project_exp: '',
        internship: '',
        price: '',
        other_advantage: '',
        cvURL: '',
    },
    advice:'',
    Cvs:[],
    SystemCurrentPath:''
})



//更新提交
const submitForm = async(id) => {

    if(state.advice!==''&&id!==''){
        console.log(id,state.advice)
        //advice和简历id打包传送到cv表
        const temp = await axios.get(`/postRecord/findByCv_idAndArticle_id?cv_id=${state.userForm.id}&article_id=${route.params.id}`)
        console.log(temp)
        let recordId = temp.data.data.id
        const res = await axios.post(`/postRecord/updateById?id=${recordId}&advice=${state.advice}`)
        console.log(res)
        if(res.data.code===0){
            ElMessage.success("建议已提交")
            ElMessage("请稍候，正在更新数据")
            location.reload()
        }
    } else if(id!==''){
        ElMessage.error("请选择一个简历再提交建议")
    } else {
        ElMessage.error("建议不能为空或未选择简历")
    }
}

const getCvs = async() => {

    state.SystemCurrentPath = await axios.get("/picture/getCurrentPath")
    console.log(state.SystemCurrentPath)

    state.Cvs = [
        {
            id: "1",
            title: "加载中...",
            job_prefer: 'cv1',
            education_exp: 'cv1',
            project_exp: 'cv1',
            internship: 'cv1',
            price: 'cv1',
            other_advantage: 'cv1',
        },
        {
            id: "2",
            title: "加载中...",
            job_prefer: 'cv2',
            education_exp: 'cv2',
            project_exp: 'cv2',
            internship: 'cv2',
            price: 'cv2',
            other_advantage: 'cv2',
        },
        {
            id: "3",
            title: "加载中...",
            job_prefer: 'cv3',
            education_exp: 'cv3',
            project_exp: 'cv3',
            internship: 'cv3',
            price: 'cv3',
            other_advantage: 'cv3',
        }
    ]

    let form = await axios.get(`/postRecord/findByArticle_id?article_id=${route.params.id}`)
    form = form.data.data
    let Cv_ids = []
    for(let i=0;i<form.length;i++){
        Cv_ids[i] = form[i].cv_id
    }
    ElMessage("正在获取数据，请稍候")
    let CvsOfThis = []
    for(let i=0;i<Cv_ids.length;i++){
        CvsOfThis[i] = (await axios.get(`/cv/findById?id=${Cv_ids[i]}`)).data.data
    }
    console.log(CvsOfThis)
    state.Cvs = CvsOfThis

}

const clickCv=(id)=>{
    let i = 0;
    for(i=0;i<state.Cvs.length;i++){
        if(state.Cvs[i].id==id) break
    }
    state.userForm.id = state.Cvs[i].id
    state.userForm.title = state.Cvs[i].title
    state.userForm.job_prefer = state.Cvs[i].job_prefer
    state.userForm.education_exp = state.Cvs[i].education_exp
    state.userForm.project_exp = state.Cvs[i].project_exp
    state.userForm.internship = state.Cvs[i].internship
    state.userForm.price = state.Cvs[i].price
    state.userForm.other_advantage = state.Cvs[i].other_advantage
    state.userForm.cvURL = state.Cvs[i].cvURL
    state.userForm.cvURL = state.SystemCurrentPath.data + "/" + state.userForm.cvURL
}

const handleCv=async(filePath)=>{
    // axios.get(`/picture/getFile?filePath=${filePath}`)
    // await axios.get(`/picture/outPut?path=${state.userForm.cvURL}`)
    console.log(filePath)
    dialogVisible.value = true
}

</script>

<style scoped lang="scss">
.el-row {
    margin-top: 20px;

    .box-card {
        text-align: center;
    }
}

.el-link {
    margin-right: 8px;
}

.el-link .el-icon--right.el-icon {
    vertical-align: text-bottom;
}

.demo-image .block {
  padding: 30px 0;
  text-align: center;
  border-right: solid 1px var(--el-border-color);
  display: inline-block;
  width: 20%;
  box-sizing: border-box;
  vertical-align: top;
}
.demo-image .block:last-child {
  border-right: none;
}
.demo-image .demonstration {
  display: block;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.el-link {
  margin-right: 8px;
}
.el-link .el-icon--right.el-icon {
  vertical-align: text-bottom;
}
</style>
